package com.zyl.commonbase.handle;

import com.zyl.commonutils.ResponseResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;


/**
 * Auther:郑誉略
 * Date: 2020-12-04 22:22
 * Description: <描述>
 */
@Slf4j
@ControllerAdvice
public class GlobalExceptionHandler {

    @ExceptionHandler(Exception.class)
    @ResponseBody
    public ResponseResult error(Exception e){
        e.printStackTrace();
        return ResponseResult.error().message("执行了全局异常处理..");
    }

    @ExceptionHandler(CourseException.class)
    @ResponseBody //为了返回数据
    public ResponseResult error(CourseException e) {
        log.error(e.getMessage());
        e.printStackTrace();

        return ResponseResult.error().code(e.getCode()).message(e.getMsg());
    }

}
